<?php

namespace app\admin\model;

use think\Model;

/**
 * Accountra
 */
class Accountra extends Model
{
    use \traits\model\SoftDelete;

    public $name = 'accountra';
    protected $autoWriteTimestamp = true;
    protected $dateFormat = 'Y-m-d H:i:s';
    protected $deleteTime = 'deletetime';
    protected $defaultSoftDelete = 0;
    protected $type = [
        'createtime' => 'timestamp',
        'updatetime' => 'timestamp',
        'deletetime' => 'timestamp',
    ];

    protected static function init()
    {
        //静态初始化
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    public function getAccTypeList()
    {
        return ['0' => __('移动'), '1' => __('联通'), '2' => __('电信'), '3' => __('广电')];
    }

    public function getAccTypeList2($key)
    {
        $arr = ['0' => __('移动'), '1' => __('联通'), '2' => __('电信'), '3' => __('广电')];
        return $arr[$key];
    }

    public function getIsYajinList()
    {
        return ['0' => __('否'), '1' => __('是')];
    }

    /**
     * 获取账号类型文本
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getAccTypeTextAttr($value, $data)
    {
        $value = $value !== null ? $value : (isset($data['acc_type']) ? $data['acc_type'] : 0);
        $list = $this->getAccTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }

    /**
     * 获取是否押金文本
     * @param $value
     * @param $data
     * @return mixed
     */
    public function getIsYajinTextAttr($value, $data)
    {
        $value = $value !== null ? $value : (isset($data['is_yajin']) ? $data['is_yajin'] : 0);
        $list = $this->getIsYajinList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
